<html>
<head>
<#assign basePath=request.contextPath>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <link href="${basePath}/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/font-awesome.min.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/form.lzy.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/good.lzy.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css"
          rel="stylesheet">
    <style>
        #page-wrapper h1 {
            display: block;
            margin-bottom: 20px;
            border-bottom: 1px solid #999;
            font-size: 16px;
            padding-left: 2px;
            font-weight: bold;
            line-height: 35px;
        }
        #fileValue {
            opacity: 0;
            width: 0px;
            height: 0px;
            font-size: 0px;
        }
        #file {
            display: inline-block;
        }
        #fileValue{ width: 0; height: 0; opacity: 0; font-size: 0;}
        .input-file-edit,.input-file-edit input,.input-file input{ width: 100%; height: 100%;}
        /*.upload-box{ min-height: 100px;}*/
        /*.input-file{ position: absolute; top: 0; left: 0; width: 100%; height: 100%;}*/
        .porduct-type label{ margin: 5px 20px 0 0;}
        .pro-box{ position: relative;}
        .pro-type-tit{ display: inline-block; width: 22px; line-height: 22px; border-radius: 50%; margin-right: 10px; background-color: #ccc; text-align: center; font-weight: bold; color: #fff;}
        .remove-btn{ position: absolute; top: 0; left: 50%; z-index: 300; width: 30px; line-height: 30px; border-radius: 50%; margin-right: 12px; background-color: #ccc; text-align: center; font-weight: bold; color: #fff;}
        .add-btn{ cursor: pointer;}
        .add-btn b{ display: inline-block; width: 30px; line-height: 30px; border-radius: 50%; margin-right: 12px; background-color: #ccc; text-align: center; font-weight: bold; color: #fff;}
    </style>
</head>
<body>

<div id="page-wrapper">
    <div class="panel panel-f5">
        <div class="panel-body row">
            <h1>● 基础信息</h1>
            <form id="Form" class="form-horizontal" method="post">
                <input type="hidden" id="_ctx" value="${basePath}"/>
                <input type="hidden" name="id" v-model="id">
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span"><font
                            color="red">*</font>&nbsp;产品名称：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="50" name="name" maxlength="50" v-model="dataObj.name"
                               placeholder="最多输入50字">
                    </div>
                </div>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span">&nbsp;<font color="red">*</font>&nbsp;产品售价：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="30" name="price" maxlength="10" min="0.01" v-model="dataObj.price"> 元
                    </div>
                </div>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span">&nbsp;<font color="red">*</font>&nbsp;产品封面：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input v-if="id" class="obj-input" name="cover" type="text" v-model="dataObj.cover">
                        <input v-else class="obj-input" name="cover" type="text">
                        <img v-if="dataObj.cover" class="obj-img" :src="dataObj.cover" width="100" height="100">
                        <img v-else class="obj-img" src="" style="display:none" width="100" height="100">
                        <span v-if="dataObj.cover" class="input-file-edit">
                            <input type="file" data-action="goods" data-image="banner"
                                   onchange="uploadImg(this)">
                        </span>
                        <span v-else class="input-file">
                            <input type="file" data-action="goods" data-image="banner"
                                   onchange="uploadImg(this)">
                        </span>
                        <span class="text-warning">封面图大小不能超过3MB，为了图片清晰美观，建议上传宽度730像素的图片。</span>
                    </div>
                </div>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4 detail-span">产品视频：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="file" data-action="icon" data-image="video" onchange="uploadFile(this,'.mp4',50)">
                        <input v-if="id" type="hidden" id="fileValue" name="video" v-model="dataObj.video">
                        <input v-else type="hidden" id="fileValue" name="video">
                        <video v-if="dataObj.video" id="fileName" controls="controls" style="max-height: 200px;" :src="dataObj.video">
                            您的浏览器不支持 video 标签。
                        </video>
                        <video v-else id="fileName" src="" controls="controls" style="display: none; max-height: 200px;">
                            您的浏览器不支持 video 标签。
                        </video>
                        <span class="text-warning text">请上传不超过50MB大小的mp4格式视频文件</span>
                    </div>
                </div>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4 detail-span">产品类型：</span>
                    <div class="col-sm-9 col-xs-8 porduct-type">
                        <label><input type="radio" name="productType" value="1" v-model="dataObj.productType"> 代理商产品</label>
                        <label><input type="radio" name="productType" value="2" v-model="dataObj.productType"> 权益产品</label>
                    </div>
                </div>
                <div class="form-group" v-if="dataObj.productType==2">
                    <span class="control-label col-sm-2 col-xs-4 detail-span">选择权益产品：</span>
                    <div class="col-sm-9 col-xs-8">
                        <select class="form-control" name="cardId" v-model="dataObj.cardId">
                            <option v-for="item in cardArr" :value="item.id">{{item.name}}</option>
                        </select>
                    </div>
                </div>
                <h1>● 详细描述</h1>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4 detail-span">产品介绍：</span>
                    <div class="col-sm-9 col-xs-8 add-box image-text">
                        <div class="btn-box first-btn-box">
                            <input class="firstText" name="firstText" value="+ 文字" type="button" @click="addText(1)">
                            <input class="firstImg" name="firstImg" value="+ 图片" type="button" @click="addImg(1)">
                        </div>
                        <div class="text-box" v-for="(item,index) in dataObj.productImageTextDtos" :key="item.id" :id="item.id" v-if="item">
                            <div v-if="item.type==1">
                                <textarea :name="'productImageTextDtos['+index+'].path'" maxlength="200" rows="3"
                                          cols="50" class="form-control" placeholder="最多输入200字">{{item.path}}</textarea>
                                <input class="sort" :name="'productImageTextDtos['+index+'].sort'" v-model="index" type="hidden"/>
                                <input :name="'productImageTextDtos['+index+'].type'" value="1" type="hidden"/>
                                <input v-if="item.productId" :name="'productImageTextDtos['+index+'].productId'" v-model="item.productId" type="hidden"/>
                            </div>
                            <div v-if="item.type==2" class="upload-box">
                                <input v-if="id && item.path" class="obj-input" :name="'productImageTextDtos['+index+'].path'" v-model="item.path" type="hidden">
                                <input v-else class="obj-input" :name="'productImageTextDtos['+index+'].path'" v-model="item.path" type="hidden">
                                <img class="obj-img" :src="item.path">
                                <span v-if="id && item.path" class="input-file-edit">
                                    <input type="file" @change="vueImg($event,'goods',index)">
                                </span>
                                <span v-else :class="item.path ? 'input-file-edit' : 'input-file'">
                                    <input type="file" @change="vueImg($event,'goods',index)">
                                </span>
                                <input class="sort" :name="'productImageTextDtos['+index+'].sort'" v-model="index" type="hidden"/>
                                <input :name="'productImageTextDtos['+index+'].type'" value="2" type="hidden"/>
                                <input v-if="item.productId" :name="'productImageTextDtos['+index+'].productId'" v-model="item.productId" type="hidden"/>
                            </div>
                            <div class="btn-box">
                                <input class="addText" name="addText" value="+ 文字" type="button" @click="addText(2,index)">
                                <input class="addImg" name="addImg" value="+ 图片" type="button" @click="addImg(2,index)">
                                <input class="remove" name="remove" value="X 删除" type="button" @click="removeBox(2,index)">
                            </div>
                        </div>
                    </div>
                </div>
                <hr/>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span"><font
                            color="red">*</font>&nbsp;合同名称：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="50" name="contractName" maxlength="50"
                               placeholder="最多输入50字" v-model="dataObj.contractName">
                    </div>
                </div>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4 detail-span"><font
                            color="red">*</font>&nbsp;上传合同：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" id="fileText" class="form-control" size="50" v-model="dataObj.contractUrl" readonly style="dataObj.contractUrl ? '' : 'display: none'" />
                        <input type="file" data-action="office" data-image="word" onchange="uploadFile(this,'.docx',10)" id="file">
                        <input v-if="id" type="text" id="fileValue" name="contractUrl" v-model="dataObj.contractUrl">
                        <input v-else type="text" id="fileValue" name="contractUrl">
                        <span class="text-warning text">请上传不超过10MB*.docx格式的标准文档</span>
                    </div>
                </div>
                <hr/>
                <div class="form-group">
					<span class="control-label col-sm-2 col-xs-4 detail-span"><span
                            class="text-red"></span> 备注：</span>
                    <div class="col-sm-10 col-xs-8 add-box">
                        <div class="text-box">
                            <textarea data-id="0" name='remark' id="remark"
                                      class="form-control" maxlength="1000" placeholder="最多输入1000字">{{dataObj.remark}}</textarea>
                        </div>
                    </div>
                </div>

                <h1>● 产品内容</h1>
                <div class="pro-box" v-for="(item, index) in dataObj.productProjectDtos">
                    <div v-if="index > 0" class="remove-btn" @click="removeType(index)">X</div>
                    <input type="hidden" :name="'productProjectDtos['+index+'].serialId'" v-model="item.serialId">
                    <input type="hidden" :name="'productProjectDtos['+index+'].type'" value="0">
                    <div class="form-group">
                        <span class="control-label col-sm-2 col-xs-4 detail-span"><b class="pro-type-tit" v-html="index+1"></b>类型：</span>
                        <div class="col-sm-9 col-xs-8">
                            <select class="form-control" :name="'productProjectDtos['+index+'].projectId'" v-model="item.projectId">
                                <option v-for="item in proType" :value="item.id" v-text="item.name"></option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <span class="control-label col-sm-2 col-xs-4 detail-span"><font
                                color="red">*</font>&nbsp;数量：</span>
                        <div class="col-sm-9 col-xs-8">
                            <input class="form-control" type="text" :name="'productProjectDtos['+index+'].containNum'" maxlength="10" v-model="item.containNum" @input="checkNum($event,index,0)">
                            <span v-if="item.proFlag[0]" class="verify-tip" style="display: block;">请输入正确的数量</span>
                        </div>
                    </div>
                    <div class="form-group" v-if="item.projectId==10">
                        <span class="control-label col-sm-2 col-xs-4 detail-span">规格：</span>
                        <div class="col-sm-9 col-xs-8">
                            <select class="form-control" :name="'productProjectDtos['+index+'].specId'" v-model="item.specId">
                                <option v-for="item in proSpec" :value="item.motorcycleId" v-text="item.motorcycleName"></option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" v-if="item.projectId==11">
                        <span class="control-label col-sm-2 col-xs-4 detail-span"><font
                                color="red">*</font>&nbsp;规格：</span>
                        <div class="col-sm-9 col-xs-8">
                            <input class="form-control" type="text" :name="'productProjectDtos['+index+'].price'" maxlength="10" v-model="item.price" @input="checkNum($event,index,1)">
                            <span v-if="item.proFlag[1]" class="verify-tip" style="display: block;">请输入正确的整数</span>
                        </div>
                    </div>
                    <div class="form-group" v-if="item.projectId==10 || item.projectId==9 || item.projectId==11">
                        <span class="control-label col-sm-2 col-xs-4 detail-span"><font
                                color="red">*</font>&nbsp;有效期设置：</span>
                        <div class="col-sm-9 col-xs-8">
                            自购买日起 <input type="text" class="form-control" :name="'productProjectDtos['+index+'].intervalDays'" maxlength="10" v-model="item.intervalDays" placeholder="留空为立即生效" @input="checkNum($event,index,3)"> 天生效，
                            有效期 <input type="text" class="form-control" :name="'productProjectDtos['+index+'].validTime'" maxlength="4" v-model="item.validTime" @input="checkNum($event,index,2)"> 天
                            <span v-if="item.proFlag[2]" class="verify-tip" style="display: block;">请输入正确的有效期</span>
                            <span v-if="item.proFlag[3]" class="verify-tip" style="display: block;">生效日留空或者输入整数</span>
                        </div>
                    </div>
                    <#--<div class="form-group">-->
                        <#--<span class="control-label col-sm-2 col-xs-4 detail-span"></span>-->
                        <#--<div class="col-sm-9 col-xs-8">-->
                            <#---->
                            <#--<select class="form-control" :name="'productProjectDtos['+index+'].type'" v-model="item.type">-->
                                <#--<option value="0">固定项</option>-->
                                <#--<option value="1">单选项</option>-->
                            <#--</select>-->
                            <#--<span class="text-warning">固定项表示用户购买产品时固定送的东西，选择项则是需要用户自行选择某样东西。</span>-->
                        <#--</div>-->
                    <#--</div>-->
                </div>

                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4 detail-span"></span>
                    <div class="col-sm-9 col-xs-8">
                        <div class="add-btn" @click="addType"><b>+</b>新增类型</div>
                    </div>
                </div>

                <h1>● 分享设置</h1>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4 detail-span">分享标签图：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input v-if="id" class="obj-input" name="sharePhone" type="text" v-model="dataObj.sharePhone">
                        <input v-else class="obj-input" name="sharePhone" type="text">
                        <img v-if="dataObj.sharePhone" class="obj-img" :src="dataObj.sharePhone" width="100" height="100">
                        <img v-else class="obj-img" src="" style="display:none" width="100" height="100">
                        <span v-if="dataObj.sharePhone" class="input-file-edit">
                            <input type="file" data-action="goods" data-image="sharePhone"
                                   onchange="uploadImg(this)">
                        </span>
                        <span v-else class="input-file">
                            <input type="file" data-action="goods" data-image="sharePhone"
                                   onchange="uploadImg(this)">
                        </span>
                        <span class="text-warning">标签图大小不能超过3MB，请使用jpg、png、bmp格式，为了图片清晰美观，请上传100*100像素的图片。</span>
                    </div>
                </div>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4 detail-span">分享标题：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="50" name="shareTitle" maxlength="30" v-model="dataObj.shareTitle"
                               placeholder="请用简洁的文字描述标题">
                    </div>
                </div>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4 detail-span">标签内容：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="50" name="shareContent" maxlength="50" placeholder="请用简洁语言描述标签分享的内容" v-model="dataObj.shareContent">
                    </div>
                </div>


                <hr>
                <div class="form-group">
                    <span class="control-label col-sm-4 col-xs-4"></span>
                    <div class="col-sm-8 col-xs-8">
                        <button type="button" class="btn btn-success" @click="submitForm"><i
                                class="fa fa-check"></i> 提交
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="${basePath}/bootstrap/js/vue.min.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/js/jquery.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/plugin/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript"
        src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/language/zh_CN.js"></script>
<script type="text/javascript">
    $(window).bootstrapValidator || document.write('<script src="${basePath}/bootstrap/js/bootstrapValidator.min.js"><\/script>' +
            '<script src="${basePath}/bootstrap/js/bootstrapValidator-zh_CN.js"><\/script>');
</script>
<script src="${basePath}/bootstrap/js/common.js" type="text/javascript"></script>
<script type="text/javascript"
        src="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript"
        src="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script>
    $(function(){
        $("#Form").data("bootstrapValidator").resetForm();
    })
    var i = 1;
    var vue = new Vue({
        el: "#page-wrapper",
        data: {
            id: null,
            proType: [],//类型组
            proSpec: [],//汽摩规格组
            defaultSpecId: "",//默认汽摩规格
            cardArr: [],
            dataObj: {
                productType: 1,
                carId: null,
                //产品内容
                productProjectDtos: [
                    {
                        projectId: 9,
                        containNum: "",
                        specId: "",
                        intervalDays: "",
                        validTime: "365",
                        type: 0,
                        price: "",
                        proFlag: [false,false,false,false]
                    }
                ],
                //图文
                productImageTextDtos: [
                    {
                        path: "",
                        type: 1,
                        id: 0
                    }
                ]

            }
        },
        created: function(){
            var _this = this;
            //如果是编辑页面 执行数据获取
            var cur = window.location.href.split("/");
            var id = cur[cur.length-1];

            //获取权益产品
            $.ajax({
                url: '${basePath}/admin/agent/product/incrementList',
                type: 'GET',
                dataType: 'json',
                data: {},
                success: function (data) {
                    if(data.result.length){
                        _this.cardArr = data.result;
                        if(!regInt.test(id)){
                            _this.dataObj.cardId = data.result[0].id;
                        }
                    }
                }
            })
            if(regInt.test(id)){
                $.ajax({
                    url: '${basePath}/admin/agent/product/queryProductById',
                    type: 'GET',
                    dataType: 'json',
                    data: {
                        id: id
                    },
                    success: function(data){
                        _this.id = id;
                        _this.dataObj = data.result;
                        var imgDto = data.result.productImageTextDtos;
                        if(imgDto){
                            for(var i=0,len=imgDto.length;i<len;i++){
                                _this.dataObj.productImageTextDtos[i].sid = imgDto[i].id
                            }
                        }
                        var proDto = data.result.productProjectDtos;
                        if(proDto){
                            for(var i=0,len=proDto.length;i<len;i++){
                                _this.dataObj.productProjectDtos[i].proFlag = [false,false,false,false];
                            }
                        }
                    },
                    error: function(){
                        console.log("error")
                    }
                }).done(function(){

                })
            }

            //获取类型
            $.ajax({
                url: '${basePath}/admin/agent/product/typeList',
                type: 'GET',
                dataType: 'json',
                data: {},
                success: function(data){
                    _this.proType = data.result.baseProductList;
                    _this.proSpec = data.result.motorcycleList;
                    if(data.result.motorcycleList){
                        _this.defaultSpecId = data.result.motorcycleList[0].motorcycleId;
                        if(_this.dataObj.productProjectDtos){
                            _this.dataObj.productProjectDtos[0].specId = data.result.motorcycleList[0].motorcycleId;
                        }
                    }
                },
                error: function(){
                    console.log("error")
                }
            })
        },
        //深度监听 网页直接就挂了...
//        watch: {
//            'dataObj.productProjectDtos': {
//                handler: function(obj, oldval){
//                    for(var i=0,len=obj.length;i<len;i++){
//                        if(obj[i].containNum < 1 || !regInt.test(obj[i].containNum)){
//                            Vue.set(obj[i].proFlag,0,true);
//                        }
//                        else{
//                            Vue.set(obj[i].proFlag,0,false);
//                        }
//                    }
//                },
//                deep: true
//            }
//        },
        methods: {
            //上传图片
            vueImg: function(e,type,index){
                //type: goods / icon ...
                var file = e.target.files[0];
                var param = new FormData(); //创建form对象
                //param.append('file',file,file.name);//通过append向form对象添加数据
                param.append('image',file);//添加form表单中其他数据
                var dto = this.dataObj.productImageTextDtos;

                if(getPhotoSize(e.target,3)) {
                    var objUrl = getObjectURL(e.target.files[0]);
                    getImageWidth(objUrl, function (w, h) {
                        var size = "?" + w + "/" + h;
                        if (w > 750) {
                            alert("图片尺寸太大，请处理成不大于750px");
                            return false;
                        }
                        else {

                            $.ajax({
                                url: '${basePath}/upload/' + type,
                                type: 'POST',
                                data: param,
                                cache: false,
                                contentType: false,
                                processData: false,
                                success: function (data) {
                                    console.log(data)
                                    //Vue.set(dto[index].path,0,data);
                                    dto[index].path = data+size;
                                },
                                error: function () {
                                    console.log("error")
                                }
                            });

                        }
                    })
                }

            },
            //校验产品内容
            checkNum: function(e,index,type){
                var dto = this.dataObj.productProjectDtos;
                var val = e.target.value;
                if(type==3){
                    if(val && !regInt.test(val)){
                        Vue.set(dto[index].proFlag,type,true);
                    }
                    else{
                        Vue.set(dto[index].proFlag,type,false);
                    }
                }
                else{
                    if(!val || !regInt.test(val)){
                        Vue.set(dto[index].proFlag,type,true);
                    }
                    else{
                        Vue.set(dto[index].proFlag,type,false);
                    }
                }
            },
            //图文
            addText: function(type,index){
                //顶部添加
                if(type==1){
                    var newObj = {
                        path: '',
                        type: 1,
                        id: i
                    };
                    this.dataObj.productImageTextDtos.unshift(newObj);
                }
                //根据index添加
                else if(type==2){
                    var newObj = {
                        path: '',
                        type: 1,
                        id: i
                    };
                    this.dataObj.productImageTextDtos.splice((index+1),0,newObj);
                }
                i++;
            },
            addImg: function(type,index){
                if(type==1){
                    var newObj = {
                        path: '',
                        type: 2,
                        id: i
                    }
                    this.dataObj.productImageTextDtos.unshift(newObj);
                }
                else if(type==2){
                    var newObj = {
                        path: '',
                        type: 2,
                        id: i
                    };
                    this.dataObj.productImageTextDtos.splice((index+1),0,newObj);
                }
                i++
            },
            removeBox: function(type,index){
                //this.dataObj.productImageTextDtos.splice(index,1)
                this.$set(this.dataObj.productImageTextDtos,index,null)
            },
            //新增类型
            addType: function(){
                var _this = this;
                var newObj = {
                    projectId: 9,
                    containNum: "",
                    specId: _this.defaultSpecId,
                    intervalDays: "",
                    validTime: "365",
                    type: 0,
                    price: "",
                    proFlag: [false,false,false,false]
                };
                this.dataObj.productProjectDtos.push(newObj);
            },
            removeType: function(obj){
                this.dataObj.productProjectDtos.splice(obj,1)
            },

            //提交
            submitForm: function(){
                var _this = this;
                var bsVal = $("#Form").data('bootstrapValidator');
                bsVal.validate();
                var url = "${basePath}/admin/agent/product/createAagntProduct";
                if(this.id){
                    url = "${basePath}/admin/agent/product/updateAagntProduct";
                }
                //校验产品内容
                var dto = this.dataObj.productProjectDtos;
                var proFlag = true;
                if(dto){
                    for(var i=0,len=dto.length;i<len;i++){
                        if(!dto[i].containNum || !regInt.test(dto[i].containNum)){
                            Vue.set(dto[i].proFlag,0,true);
                            proFlag = false;
                        }
                        //代金券规格
                        else if(dto[i].projectId==11 && !dto[i].price){
                            Vue.set(dto[i].proFlag,1,true);
                            proFlag = false;
                        }
                        //汽摩券、房车券
                        else if(dto[i].projectId==10 || dto[i].projectId==9 || dto[i].projectId==11){
                            //有效期
                            if(!dto[i].validTime || !regInt.test(dto[i].validTime)){
                                Vue.set(dto[i].proFlag,2,true);
                                proFlag = false;
                            }
                            //生效日
                            else if(dto[i].intervalDays && !regInt.test(dto[i].intervalDays)){
                                Vue.set(dto[i].proFlag,3,true);
                                proFlag = false;
                            }
                        }
                        else{
                            Vue.set(dto[i].proFlag,0,false);
                            Vue.set(dto[i].proFlag,1,false);
                            Vue.set(dto[i].proFlag,2,false);
                            Vue.set(dto[i].proFlag,3,false);
                            proFlag = true;
                        }
                    }
                }
                if (bsVal.isValid()) {
                    if(proFlag){
                        layer.load(2);
                        $.ajax({
                            type: 'GET',
                            dataType: 'json',
                            url: url,
                            data: $("#Form").serialize(),
                            success: function (data) {
                                if (data.code == '0') {
                                    layer.alert('操作成功', {
                                        icon: 1
                                    }, function () {
                                        window.location.href = '${basePath}/admin/agent/product';
                                    })
                                } else {
                                    layer.alert(data.desc, {
                                        icon: 5
                                    });
                                }
                            },
                            error: function () {
                                layer.alert('系统错误', {
                                    icon: 5
                                });
                            },
                            complete: function(){
                                layer.closeAll('loading');
                            }
                        });
                    }
                }
                else {
                    var smallTop = $("small:visible").eq(0).offset().top - 50;
                    $("html,body").animate({scrollTop: smallTop}, 300);
                }
            }
        },
        mounted: function(){
            //表单验证
            $('#Form').bootstrapValidator({
                fields: {
                    name: {
                        trigger: "focus blur",
                        validators: {
                            notEmpty: {
                                message: '请输入产品名称'
                            }
                        }
                    },
                    price: {
                        validators: {
                            notEmpty: {
                                message: '请输入产品售价'
                            },
                            regexp: {
                                regexp: regPrice,
                                message: '请输入最多两位小数的数字'
                            }
                        }
                    },
                    cover: {
                        trigger: "change",
                        validators: {
                            notEmpty: {
                                message: '请上传产品封面'
                            }
                        }
                    },
                    contractName:{
                        trigger: "focus blur",
                        validators: {
                            notEmpty: {
                                message: '请输入合同名称'
                            }
                        }
                    },
                    contractUrl:{
                        trigger: "change",
                        validators: {
                            notEmpty: {
                                message: '请上传合同'
                            }
                        }
                    }
                }
            });
        }
    })

    function getImageWidth(url,callback){
        var img = new Image();
        img.src = url;
        // 如果图片被缓存，则直接返回缓存数据
        if(img.complete){
            callback(img.width, img.height);
        }
        // 完全加载完毕的事件
        else{
            img.onload = function(){
                callback(img.width, img.height);
            }
        }
    }
    //判断图片大小
    function getPhotoSize(obj,imgSize){
        var photoExt = obj.value.substring(obj.value.lastIndexOf(".")+1).toLowerCase();//获得文件后缀名
        if(photoExt!='jpg'&&photoExt!='jpeg'&&photoExt!='bmp'&&photoExt!='png'&&photoExt!='gif'){
            alert("图片格式必须是.jpg/.jpeg/.bmp/.png!");
            return false;
        }
        var imgSize = imgSize || 3;
        var fileSize = 0;
        var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
        if (isIE && !obj.files) {
            var filePath = obj.value;
            var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
            var file = fileSystem.GetFile (filePath);
            fileSize = file.Size;
        }else {
            fileSize = obj.files[0].size;
        }
        fileSize=Math.round(fileSize/1024*100)/100; //单位为KB
        if(fileSize>imgSize*1024){
            alert("图片最大为"+imgSize+"M，请重新上传!");
            return false;
        }
        return fileSize;
    }
    function getObjectURL(file) {
        var url = null ;
        if (window.createObjectURL!=undefined) { // basic
            url = window.createObjectURL(file) ;
        } else if (window.URL!=undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file) ;
        } else if (window.webkitURL!=undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file) ;
        }
        return url ;
    }

</script>
</body>
</html>
